<template>
	<view class="app">
		<view class="price-box">
			<text>支付金额</text>
			<text class="price">{{data.order.pay_price}}</text>
		</view>

		<view class="pay-type-list">
			<view v-for="(item,index) in data.pay_type" :key="index" class="type-item b-b"
				@click="changePayType(item.name)">
				<view style="width: 60rpx; height: 60rpx;margin-right: 20rpx;">
					<u-image :src="item.icon" width="100%" height="100%"></u-image>
				</view>
				<view class="con">
					<text class="tit">{{item.title}}</text>
					<text v-if="item.recommend == 1">推荐使用{{item.title}}</text>
					<text v-if="item.show_balance == 1">可用余额 ¥{{data.balance}}</text>
				</view>
				<label class="radio">
					<radio value="" color="#fa436a" :checked="item.select"></radio>
				</label>
			</view>
		</view>

		<text class="mix-btn" @click="confirm">确认支付</text>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				payType: 1,
				orderInfo: {},
				data: null
			};
		},
		computed: {

		},
		onLoad(options) {
			let data = JSON.parse(options.data);
			this.data = data

			for (let i = 0; i < data.pay_type.length; i++) {
				if (data.pay_type[i].recommend == 1) {
					this.payType = data.pay_type[i].name
					data.pay_type[i].select = true
				}
			}
		},

		methods: {
			//选择支付方式
			changePayType(type) {
				this.payType = type;
				for (let i = 0; i < this.data.pay_type.length; i++) {
					this.data.pay_type[i].select = false
					if (this.data.pay_type[i].name == type) {
						this.data.pay_type[i].select = true
					}
				}
			},
			//确认支付
			confirm: async function() {
				let that = this;
				this.$u.api.rechangePayment({
					order_id: that.data.order.id,
					pay_type: that.payType,
				}).then(res => {
					uni.requestPayment({
						provider: 'wxpay',
						orderInfo: 'order_id:'+that.data.order.id,
						timeStamp: res.timestamp,
						nonceStr: res.nonceStr,
						package: res.package,
						signType: res.signType,
						paySign: res.paySign,
						success: function(res) {
							that.$u.route({
								url: '/pages/rechange/paySuccess'
							})
						},
						fail: function(err) {
							that.$api.msg("支付失败"+err);
						}
					})
				})
			},
		}
	}
</script>

<style lang='scss'>
	.app {
		width: 100%;
	}

	.price-box {
		background-color: #fff;
		height: 265upx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 28upx;
		color: #909399;

		.price {
			font-size: 50upx;
			color: #303133;
			margin-top: 12upx;

			&:before {
				content: '￥';
				font-size: 40upx;
			}
		}
	}

	.pay-type-list {
		margin-top: 20upx;
		background-color: #fff;
		padding-left: 60upx;

		.type-item {
			height: 120upx;
			padding: 20upx 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-right: 60upx;
			font-size: 30upx;
			position: relative;
		}

		.icon {
			width: 100upx;
			font-size: 52upx;
		}

		.icon-erjiye-yucunkuan {
			color: #fe8e2e;
		}

		.icon-weixinzhifu {
			color: #36cb59;
		}

		.icon-alipay {
			color: #01aaef;
		}

		.tit {
			font-size: $font-lg;
			color: $font-color-dark;
			margin-bottom: 4upx;
		}

		.con {
			flex: 1;
			display: flex;
			flex-direction: column;
			font-size: $font-sm;
			color: $font-color-light;
		}
	}

	.mix-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 630upx;
		height: 80upx;
		margin: 80upx auto 30upx;
		font-size: $font-lg;
		color: #fff;
		background-color: $base-color;
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}
</style>
